import { def } from "./utils";
// 得到array.prototype
const arrayPrototype = Array.prototype;
// 已prototype为原型，创建arrayMethods对象
const arrayMethods = Object.create(arrayPrototype);
// 重写的方法
const methodsNeedChange = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'];
methodsNeedChange.forEach((method) => {
  const original = arrayPrototype[method]
  def(arrayMethods, method, function () {
    // 取出__ob__;
    // 再新增的时候使用：push\unshit\splice
    const ob = this.__ob__;
const args = [...arguments]

    let inserted = [];
    switch (method) {
      case 'push': break;
      case 'unshift': inserted == arguments; break;
      case 'splice': args.slice(2); break;
    }
    if (inserted) {
      ob.observeArray(inserted);
    }
    ob.dep.notifi();
    console.log("Asasassssss")
    return original.apply(this, arguments)
  }, false)
})

export default arrayMethods;